package com.qianfeng.volleytest;


import android.app.DownloadManager;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.ImageRequest;
import com.android.volley.toolbox.NetworkImageView;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import java.util.HashMap;
import java.util.Map;


public class MainActivity extends AppCompatActivity {
    private RequestQueue queue;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



    }
    //第一步   创建请求队列
    //第二步 创建请求
    //第三步 设置tag（用来取消请求的）
    //第四步 将请求添加到请求队列
    //第五步 取消请求
        private void StringRequestMethod(){
            queue = Volley.newRequestQueue(this);
            StringRequest request = new StringRequest(Request.Method.GET, "", new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            });
            request.setTag(this);
            queue.add(request);
        }

    @Override
    protected void onStop() {
        super.onStop();
        queue.cancelAll(this);
    }
    //post请求传递参数
    StringRequest request = new StringRequest(Request.Method.POST, "", new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    }){
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            HashMap<String,String>hashMap = new HashMap<>();
            hashMap.put("","");
            return hashMap;
        }
    };
    //图片处理
    private void imageRequestMethod(){
        ImageRequest request = new ImageRequest("", new Response.Listener<Bitmap>() {

            @Override
            public void onResponse(Bitmap response) {

            }
        }, 300, 300, ImageView.ScaleType.FIT_XY, Bitmap.Config.ARGB_8888, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        request.setTag(this);
        queue.add(request);
      //第一步   实例化RequestQueue
        //第二部  实例化ImageCache
        //第三步   实例化Imageloader
        //第四步   实例化ImageListener
        //第五步   调用imageload。get方法显示图片

    }
    private void imageLoadMethod(){

    }
    //实现网络图片的加载
    private void netWorkImageView(){
      //  ImageLoader loader = new ImageLoader(queue,AppImageCache.getAppImageCache);
//        NetworkImageView networkImageView = this.findViewById(R.id.)
//        networkImageView.setDefaultImageResId(R.mipmap.ic_launcher);
//        networkImageView.setErrorImageResId(R.);
//        networkImageView.setImageUrl(imageUrl,loader);
    }
}
